package com.example.qing.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.qing.mapper.EmpMapper;
import com.example.qing.pojo.Emp;
import com.example.qing.pojo.PageBean;
import com.example.qing.service.EmpService;

import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {

    @Resource
   private EmpMapper empMapper;


/*
    @Override
    public PageBean page(Integer page, Integer pagesize, String name, Short gender, LocalDate begin, LocalDate end) {
*/
/*
        PageHelper.startPage(page,pagesize);
        QueryWrapper<Emp>wrapper=new QueryWrapper<Emp>();
        if(name!=null && name!=" ") wrapper.like("name",name);
        if(gender!=null)wrapper.eq("gender",gender);
        if(begin!=null&&end!=null) wrapper.between("entryDate",begin,end);

        List<Emp>empList=empMapper.selectList(wrapper);
        Page<Emp>p= (Page<Emp>)empList;
        PageBean pageBean=new PageBean(p.getTotal(),p.getResult());*//*

        return pageBean;
    }
*/

    @Override
    public void delete(List<Integer> ids) {
        empMapper.deleteByIds(ids);
    }

    @Override
    public void save(Emp emp) {
        emp.setName("123456");
        Short gender=1;
        emp.setGender(gender);

        emp.setCreateTime(LocalDateTime.now());
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.insert(emp);
    }

    @Override
    public Emp getById(Integer id) {
        return empMapper.selectById(id);
    }

    @Override
    public void update(Emp emp) {
        empMapper.updateById(emp);
    }

    @Override
    public Emp login(Emp emp) {
        QueryWrapper<Emp>queryWrapper=new QueryWrapper<Emp>()
                .eq("username",emp.getUsername())
                .eq("password",emp.getPassword());
        return empMapper.selectOne(queryWrapper);
    }

    @Override
    public void register(Emp emp) {
        QueryWrapper<Emp>queryWrapper=new QueryWrapper<Emp>()
                .eq("username",emp.getUsername());
        Emp dbemp=empMapper.selectOne(queryWrapper);
        if (dbemp != null) {

        }
    }


}
